/**
 * edurender
 * Quake3Model.fx
 * (c) 2009 J. Brad Byrd
 */

float4x4 g_mvp;

struct VsIn
{
	float3 position : POSITION;
	float3 normal : NORMAL;
};

struct VsToPs
{
	float4 position : SV_POSITION;
	float3 diffuse : COLOR0;
};

struct PsOut
{
	float4 diffuse : SV_TARGET;
};

VsToPs VsMain(VsIn input)
{
	VsToPs output;
	output.position = mul(float4(input.position, 1.0f), g_mvp);
	output.diffuse = saturate(dot(input.normal, float3(0.0f, 0.0f, 1.0f))) + 0.2f;
	//output.diffuse = input.normal;
	return output;
}

PsOut PsMain(VsToPs input, uint prim : SV_PRIMITIVEID)
{
	PsOut output;
	//output.diffuse.rgb = float3(0.0f, 1.0f, 0.0f);
	/*
	output.diffuse.r = (prim + 0) % 3 == 0;
	output.diffuse.g = (prim + 1) % 3 == 0;
	output.diffuse.b = (prim + 2) % 3 == 0;
	output.diffuse.rgb *= input.diffuse;
	*/
	
	output.diffuse.rgb = input.diffuse;
	
	//output.diffuse.rgb = saturate(dot(input.diffuse, float3(0.0f, 0.0f, 1.0f))) + 0.2f;
	
	output.diffuse.a = 1.0f;

	return output;
}

DepthStencilState dss
{
};

RasterizerState rs
{
	FrontCounterClockwise = True;
};

technique10 Quake3Model
{
	pass
	{
		SetVertexShader(CompileShader(vs_4_0, VsMain()));
		SetGeometryShader(NULL);
		SetPixelShader(CompileShader(ps_4_0, PsMain()));

		SetDepthStencilState(dss, 0);
		SetRasterizerState(rs);
	}
}
